package Services

import(
	"github.com/gin-gonic/gin"
	"fmt"
	"net/http"
	"gin/Databases"
	"gin/Middlewares"
	"strconv"
)

// 宏观数据
func OverallDataUpdate(c *gin.Context) {
	if (!Middlewares.CheckLogin(c)) {
		c.JSON(http.StatusOK, gin.H{
	        "result": -1,
	        "msg":    "login fail",
	        "data": "{}",
	    })
	    return
	}

	title := c.Query("title")
	url := c.Query("url")
	site := c.Query("site")
	date := c.Query("date")
	etype, _ := strconv.Atoi(c.Query("type"))
	id, _ := strconv.Atoi(c.Query("id"))

	sql := "update macro_data_temp set Fdate=?,Ftype=?,Ftitle=?,Furl=?,Fsite=?,Fstatus=0,Fmodify_time=now() where Fid=?;"
	_,err := Databases.Db.Exec(sql, date, etype, title, url, site, id)
	if err != nil {
		c.JSON(http.StatusOK, gin.H{
	        "result": -1,
	        "msg":    "insert fail",
	        "data": "{}",
	    })
		fmt.Println("insert failed, ", err)
		return
	}

    c.JSON(http.StatusOK, gin.H{
        "result": 0,
        "msg":    "success",
        "data": "",
    })
}

